var t = require("../../api.js"), a = getApp(), i = !1, e = !0, s = null;

Page({
    data: {
        naver: "order",
        status: -1,
        intval: [],
        p: 1
    },
    onLoad: function(t) {
        a.pageOnLoad(this, t);
        var i = this;
        void 0 == t.status && (t.status = -1), i.setData(t), i.getList();
    },
    getList: function() {
        var i = this;
        wx.showLoading({
            title: "加载中"
        }), a.request({
            url: t.bargain.order_list,
            data: {
                status: i.data.status || -1
            },
            success: function(t) {
                0 == t.code ? (i.setData(t.data), i.setData({
                    p: 1
                }), i.getTimeList()) : i.showLoading({
                    title: t.msg
                });
            },
            complete: function(t) {
                wx.hideLoading(), e = !1;
            }
        });
    },
    getTimeList: function() {
        clearInterval(s);
        var t = this, a = t.data.list;
        s = setInterval(function() {
            for (var i in a) if (a[i].reset_time > 0) {
                var e = a[i].reset_time - 1, s = t.setTimeList(e);
                a[i].reset_time = e, a[i].time_list = s;
            }
            t.setData({
                list: a
            });
        }, 1e3);
    },
    onReady: function() {
        a.pageOnReady(this);
    },
    onShow: function() {
        a.pageOnShow(this);
    },
    onHide: function() {
        a.pageOnHide(this);
    },
    onUnload: function() {
        a.pageOnUnload(this);
    },
    onReachBottom: function() {
        var t = this;
        e || t.loadData();
    },
    loadData: function() {
        var s = this;
        if (!i) {
            i = !0, wx.showLoading({
                title: "加载中"
            });
            var n = s.data.p + 1;
            a.request({
                url: t.bargain.order_list,
                data: {
                    status: s.data.status,
                    page: n
                },
                success: function(t) {
                    if (0 == t.code) {
                        var a = s.data.list.concat(t.data.list);
                        s.setData({
                            list: a,
                            p: n
                        }), 0 == t.data.list.length && (e = !0), s.getTimeList();
                    } else s.showLoading({
                        title: t.msg
                    });
                },
                complete: function(t) {
                    wx.hideLoading(), i = !0;
                }
            });
        }
    },
    submit: function(t) {
        var a = [], i = [];
        i.push({
            bargain_order_id: t.currentTarget.dataset.index
        }), a.push({
            mch_id: 0,
            goods_list: i
        }), wx.navigateTo({
            url: "/pages/new-order-submit/new-order-submit?mch_list=" + JSON.stringify(a)
        });
    }
});